<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item  label="" class="item-three">
					<el-select v-model="dataForm.appTypes" placeholder="订单类型">
            <el-option label="全部" value="" ></el-option>
						<el-option label="安卓用户端" value="0" ></el-option>
						<el-option label="安卓商家端" value="1" ></el-option>
            <el-option label="iOS用户端" value="2" ></el-option>
						<el-option label="iOS商家端" value="3" ></el-option>
					</el-select>
			</el-form-item>
      <el-form-item label="上架时间" class="item-date">
            <el-date-picker
            v-model="dataForm.startTime"
            type="datetime"
            value-format = "yyyy-MM-dd HH:mm:ss"
            placeholder="开始时间"
            :editable="false">
          </el-date-picker>
          <span class="span-to">~</span>
          		<el-date-picker
              v-model="dataForm.endTime"
              type="datetime"
              value-format = "yyyy-MM-dd HH:mm:ss"
              placeholder="截止时间"
              :editable="false">
            </el-date-picker>
			</el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('generator:shoppingandroidapp:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <el-button v-if="isAuth('app:version:addAppVersion')" type="primary" @click="addOrUpdateHandle1()">安卓上传</el-button>
        <el-button v-if="isAuth('app:version:addAppVersion')" type="primary" @click="addOrUpdateHandle2()">IOS上传</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间"
        width="160px">
      </el-table-column>
      <el-table-column
        prop="masterVer"
        header-align="center"
        align="center"
        label="主版本号">
      </el-table-column>
      <el-table-column
        prop="assistVer"
        header-align="center"
        align="center"
        label="内部版本号">
      </el-table-column>
      <el-table-column
        prop="downUrl"
        header-align="center"
        align="center"
        label="下载地址"
        width="500px">
      </el-table-column>
      <el-table-column
        prop="updateTime"
        header-align="center"
        align="center"
        label="更新时间"
        width="160px">
      </el-table-column>
      <el-table-column
        prop="mustBe"
        header-align="center"
        align="center"
        label="是否强制升级">
        <template slot-scope="scope">
          <span v-if="scope.row.mustBe == 1">
            <span v-if="scope.row.appType === '1' || scope.row.appType === '0'">强制</span>
          </span>
          <span v-if="scope.row.mustBe == 0">
            <span v-if="scope.row.appType === '1' || scope.row.appType === '0'">不强制</span>
          </span>
          <span v-if="scope.row.strongUpdateApp == 0">
            <span v-if="scope.row.appType === '2' || scope.row.appType === '3'">不强制</span>
          </span>
          <span v-if="scope.row.strongUpdateApp == 1">
            <span v-if="scope.row.appType === '2' || scope.row.appType === '3'">强制</span>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="appType"
        header-align="center"
        align="center"
        label="App类型">
        <template slot-scope="scope">
          <span v-if="scope.row.appType == 0">安卓用户端</span>
          <span v-if="scope.row.appType == 1">安卓商家端</span>
          <span v-if="scope.row.appType == 2">IOS用户端</span>
          <span v-if="scope.row.appType == 3">IOS商家端</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">查看</el-button>
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <addversionandroid v-if="addOrUpdateVisible" ref="addversionandroidRef" @refreshDataList="getDataList"></addversionandroid>
    <addversionios v-if="addOrUpdateVisible" ref="addversioniosRef" @refreshDataList="getDataList"></addversionios>
  </div>
</template>

<script>
  import AddOrUpdate from './shoppingandroidapp-add-or-update'
  import addversionandroid from './addversionandroid'
  import addversionios from './addversionios'
  export default {
    data () {
      return {
        dataForm: {
          appTypes: '',
          startTime: '',
          endTime: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate,
      addversionandroid,
      addversionios
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/app/version/queryVersionList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'appTypes': this.dataForm.appTypes,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      addOrUpdateHandle1 () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addversionandroidRef.init()
        })
      },
      addOrUpdateHandle2 () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addversioniosRef.init()
        })
      }
      // 删除
      // deleteHandle (id) {
      //   var ids = id ? [id] : this.dataListSelections.map(item => {
      //     return item.id
      //   })
      //   this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
      //     confirmButtonText: '确定',
      //     cancelButtonText: '取消',
      //     type: 'warning'
      //   }).then(() => {
      //     this.$http({
      //       url: this.$http.adornUrl('/generator/shoppingandroidapp/delete'),
      //       method: 'post',
      //       data: this.$http.adornData(ids, false)
      //     }).then(({data}) => {
      //       if (data && data.code === 0) {
      //         this.$message({
      //           message: '操作成功',
      //           type: 'success',
      //           duration: 1500,
      //           onClose: () => {
      //             this.getDataList()
      //           }
      //         })
      //       } else {
      //         this.$message.error(data.msg)
      //       }
      //     })
      //   })
      // }
    }
  }
</script>
